package com.own.demo.enumv2;




import com.own.demo.constants.CommonConstant;

import java.math.BigDecimal;

/**
 * 围栏创建类型枚举
 *
 * @author heguanglong
 * @date 2020-12-02
 */
public enum GpsTypeEnums {

    /**
     * WGS84
     */
    COORDINATE_SYSTEM_WGS84(1, "WGS84"),
    /**
     * GCJ02
     */
    COORDINATE_SYSTEM_GCJ02(2, "GCJ02"),
    /**
     * BD0911
     */
    COORDINATE_SYSTEM_BD0911(3, "BD0911");
    private Integer id;
    private String name;


    GpsTypeEnums(Integer id, String name) {
        this.name = name;
        this.id = id;
    }

    public static GeoPoint gpsToGcJo2(double lat, double lon, Integer type) {
        if (COORDINATE_SYSTEM_BD0911.getId().equals(type)) {
            return GpsFormat.bd09ToGcj02(lat, lon);
        } else if (COORDINATE_SYSTEM_WGS84.getId().equals(type)) {
            return GpsFormat.wgs84ToGcj02(lat, lon);
        }
        return null;
    }

    public static GeoPoint gpsToGcJo2New(double lat, double lon, Integer type) {
        GeoPoint geoPoint=null;
        if (COORDINATE_SYSTEM_BD0911.getId().equals(type)) {
            geoPoint= GpsFormat.bd09ToGcj02(lon, lat);
        } else if (COORDINATE_SYSTEM_WGS84.getId().equals(type)) {
            geoPoint= GpsFormat.wgs84ToGcj02(lon,lat);
        }else{
            geoPoint=  new GeoPoint(lon, lat);
        }
        geoPoint.setX(geoPoint.getX());
        geoPoint.setY(geoPoint.getY());
        return geoPoint;
    }


    public static GeoPoint getGeoPoint(Integer y,Integer x, Integer type) {
        BigDecimal lat = new BigDecimal(y == null ? CommonConstant.ZERO : y);
        BigDecimal lng = new BigDecimal(x == null ? CommonConstant.ZERO : x);
        BigDecimal b2 = new BigDecimal(CommonConstant.MILLION);
        double vLng = lng.divide(b2, CommonConstant.SIX, BigDecimal.ROUND_FLOOR).doubleValue();
        double vLat = lat.divide(b2, CommonConstant.SIX, BigDecimal.ROUND_FLOOR).doubleValue();
        GeoPoint gpsPoint = GpsTypeEnums.gpsToGcJo2(vLng, vLat, type);
        GeoPoint returnPoint = gpsPoint != null ? gpsPoint : new GeoPoint(vLng, vLat);
        returnPoint.setX(returnPoint.getX());
        returnPoint.setY(returnPoint.getY());
        return returnPoint;
    }


    public static void main(String[] args) {
//116.74202499389648,39.82237650553385
        //116.742024,39.822376
        GeoPoint geoPoint = GpsTypeEnums.getGeoPoint(39822376,116742024, 3);
        System.out.println(geoPoint.getX()+","+geoPoint.getY());
//        115.561264,38.237863
//        String data="115.561264,38.237863,220318171956,10.0,0,269,0";
//        String[] pointArr = data.split("\\,", -1);
//        double lat = Double.valueOf(pointArr[1]);
//        double lon = Double.valueOf(pointArr[0]);
//        GeoPoint gpsPoint = GpsTypeEnums.gpsToGcJo2New(lat, lon, 2);
//        System.out.println(gpsPoint.getX()+","+gpsPoint.getY());
    }

    public static void formatGps(GeoPoint returnPoint ){
        returnPoint.setX(returnPoint.getX());
        returnPoint.setY(returnPoint.getY());
    }

    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }
}
